package com.huaiyi.fms.open.authorization;

import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;

public class TokenUtil {

    public static String getToken(String host, int port, String appKey, String appSecret) {
        HttpResponse httpResponse = HttpRequest.get(UrlBuilder.ofHttp("/open/authorization/access_token")
                .addQuery("appKey", appKey)
                .addQuery("appSecret", appSecret)
                .setHost(host)
                .setPort(port).build()).execute();
        System.out.println("返回数据:"+httpResponse.body());
        if (httpResponse.isOk()) {
            return JSONUtil.parseObj(httpResponse.body()).getStr("data");
        }
       throw new RuntimeException("获取token失败:"+httpResponse);
    }

}
